<template>
	<view>
		审核视频
		<!-- 视频列表 -->
		  <scroll-view class="video-list" scroll-y>
			  <view class="video-container">
				  <view class="video-item" v-for="(item, index) in videos" :key="index">
					<view class="author-info-container">
						<view class="pic">
							<!-- <image src="/static/cy-my/pic-m1.png" style="height: 4%;" mode="widthFix">
							</image> -->
							<u-avatar :src="item.user.avatarUrl"></u-avatar>
						</view>
						<view class="txt" >
							<view class="name" >
								<view class="h3">
									{{item.user.nickname}}
								</view>
								<view class="phone">
									{{item.createTime}}
								</view>
							</view>
						</view>
					</view>
					<view class="check-container">
					<image class="cover" :src="item.coverUrl" style="width: 100%; height: 100%; border-radius: 10px;" mode="widthFix" @click="goToPage(item.url)"></image>
					<view class="button-container">
					<button class="check-button1" @click="allow(item.id)" >√</button>
					
					<button class="check-button2" @click="refuse(item.id)">×</button>
					</view>
					</view>
					<view class="text-container" @click="goToPage(item.id)">
						<text class="title">{{item.title}}</text>
						<text class="info">{{item.introduction}}</text>
					</view>
					
					
				  </view>
			  </view>
		  </scroll-view>
		</view>
	</view>

  
</template>

<script>
export default {
  data() {
    return {
		current:'1',
		pageSize:"999",
      // 视频数据
      videos: [
        {
          cover: "/static/video-cover/1.jpg",
          title: "这是一个视频标题",
          info: "视频副标题：描述",
          url: "/pages/video-detail/video-detail",
		  timebefore: "1h前发布",
        },
        {
          cover: "/static/video-cover/4.jpg",
          title: "这是另一个视频标题",
          info: "视频副标题：描述",
          url: "/pages/video-detail/video-detail",
		  timebefore: "2h前发布",
        },
        {
          cover: "/static/video-cover/5.jpg",
          title: "这是第三个视频标题",
          info: "视频副标题：描述",
          url: "/pages/video-detail/video-detail",
		  timebefore: "3h前发布",
        },
		{
		  cover: "/static/video-cover/6.jpg",
		  title: "第四个视频标题",
		  info: "视频副标题：描述",
		  url: "/pages/video-detail/video-detail",
		  timebefore: "41h前发布",
		}
      ],
      // 当前选中的分类索引
      active: 0,
      // 搜索关键词
      keyword: ""
    };
  },
  onPullDownRefresh(){
  		  console.log("刷新审核页面")
  uni.request({
  	  	method:'GET',
  	  	url:"http://47.97.114.13:8080/api/video/list/waiting",
	  		  header: {
	  			"Authorization": this.$store.state.token,
	  			// this.$store.state.token,
	  		  },
			  data: {
			  	  	current: this.current,
			  	  	pageSize: this.pageSize,
			  },
  	  })
  	  .then(res => {
	  			console.log("获取审核视频列表");
				console.log(res)
	  			//console.log(this.videos);
				if(res[1].data.success!=true)
				{
					uni.showModal({
									title: "提示",
									content: res[1].data.message,
									showCancel:false,
									success: function (res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
				}
				else
				{
					this.videos = res[1].data.data.list;
				}

  	  })
    					  uni.stopPullDownRefresh()
  	      },
  methods: {
	  requestVideoInfo(){
	  	return new Promise((resolve, reject) => {
	  		uni.request({
	  		  method: 'GET',
	  		  url: "http://47.97.114.13:8080/api/video/list/waiting",
	  		  header: {
	  			"Authorization": this.$store.state.token,
	  			// this.$store.state.token,
	  		  },
	  		  data: {
	  			current: this.current,
	  			pageSize: this.pageSize,
	  		  },
	  		  success: (res) => {
				  
	  			console.log("获取审核视频列表");
	  			//console.log(this.videos);
								console.log(res)
				if(res.data.success!=true)
				{
					uni.showModal({
									title: "提示",
									content: res.data.message,
									showCancel:false,
									success: function (res) {
										if (res.confirm) {
											console.log('用户点击确定');
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
				}
				else
				{
					this.videos = res.data.data.list;
				}
	  			resolve();
	  		  },
	  		  fail: (err) => {
	  			reject(err);
	  		  }
	  		});
	  	});
	  },
	    
	  async onLoad() {
	  	console.log("渲染之前");
	  	await this.requestVideoInfo(); // 使用async/await语法处理异步操作
	    // 阻塞操作完成后继续渲染页面
	  },
    // 跳转到视频页面
    goVideo(item) {
      uni.navigateTo({
        url: item.url
      });
    },
	goToPage(url) {
		
		// if (!url) return;
		uni.navigateTo({
			url: url
		});
	},
	allow(id){
		console.log(id)
		uni.request({
			  	method:'POST',
			  	url:"http://47.97.114.13:8080/api/video/"+id+"/approve/",
			  		  header: {
			  			"Authorization": this.$store.state.token,
			  			// this.$store.state.token,
			  		  },
			  })
			  .then(res => {
			  			console.log("同意审核");
						console.log(res)
			  			//console.log(this.videos);
						if(res[1].data.success!=true)
						{
							uni.showModal({
											title: "提示",
											content: res[1].data.message,
											showCancel:false,
											success: function (res) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
						}
						else
						{
							uni.showToast({
								title: res[1].data.message,
								icon: "none"
							})
						}
		
			  })

	},
	
	refuse(id){
		uni.request({
			  	method:'POST',
			  	url:"http://47.97.114.13:8080/api/video/"+id+"/reject/",
			  		  header: {
			  			"Authorization": this.$store.state.token,
			  			// this.$store.state.token,
			  		  },
			  })
			  .then(res => {
			  			console.log("不同意审核");
						console.log(res)
			  			//console.log(this.videos);
						if(res[1].data.success!=true)
						{
							uni.showModal({
											title: "提示",
											content: res[1].data.message,
											showCancel:false,
											success: function (res) {
												if (res.confirm) {
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
						}
						else
						{
							uni.showToast({
								title: res[1].data.message,
								icon: "none"
							})
						}
		
			  })

	}
  }
};
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.item {
   font-size :28rpx; 
   margin :10rpx; 
   color :#999999
}
.active {
   color :#ff0000
}
.video-list {
   width :95%;
   margin: 0 auto;
}
.video-container{
}
.button-container{
	display: flex;
	flex-direction: column;
}
.check-button1{
	height: 150rpx;
	width:150rpx;
	color:limegreen;
	font-size: 70rpx;
}
.check-button2{
	height: 150rpx;
	width:150rpx;
	color:red;
	font-size: 70rpx;
	padding-bottom: 50rpx;
}

.author-info-container{
	padding-top: 3%;
	padding-bottom: 1%;
	padding-left: 1%;
	display: flex;
	justify-content: flex-start;
}
.pic {
	width : 10%;
	float: left;
}

.txt {
	/* clear: both;
	padding: 20rpx 0;
	width: 80%;
	overflow: hidden; */
	margin-left: 10px;
}

.txt .name {
	position: relative;
	display: block;
}

.txt .name .h3 {
	font-size: 26rpx;
	margin-bottom: 6rpx;
	font-weight: bold;
}

.txt .name .phone {
	height: 40rpx;
	line-height: 40rpx;
	font-size: 20rpx;
	width: 330rpx;
	background-size: 100rpx;
	color: rgb(68, 68, 68);
}



.video-item {
   width: 98%;
   margin-bottom: 2px;
}
.cover {
   width :55%; 
   height :300rpx
}
.text-container {
    display: flex;
    flex-direction: column;
    padding-left: 10rpx;
    padding-right: 10rpx;
    padding-bottom: 10rpx;
	margin-right: 80rpx;
}
.check-container{
	display: flex;
	padding-left: 10rpx;
	padding-right: 10rpx;
	padding-bottom: 10rpx;
}
.title {
   font-size :28rpx; 
   padding-left :10rpx; 
   padding-right :10rpx
}
.info {
   font-size :24rpx; 
   color :#999999; 
   padding-left :10rpx; 
   padding-right :10rpx; 
   padding-bottom :10rpx
}

 .head-nav{
    width: 50%;
    margin:20rpx auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .activite{
    font-weight: bold;
    border-bottom: 6rpx solid #0065d9;
  }
  .head-nav>view{
    padding-bottom: 10rpx;
  }
  .box{background: #008000;}

</style>